package com.wyf.mapper;

import com.wyf.pojo.User;
import lombok.Data;
import org.mybatis.spring.SqlSessionTemplate;

import java.util.List;

@Data
public class UserMapperImpl implements UserMapper {
    // 我们的所有操作，都是用SQLSession来执行，在原来，我们都使用SQLSessionTempplate
    private SqlSessionTemplate sqlSession;

    @Override
    public List<User> selectUser() {
        User xiaowang = new User(8, "xiaowang", "888");

        UserMapper mapper = sqlSession.getMapper(UserMapper.class);

        mapper.addUser(xiaowang);
        mapper.deleteUser(8);

        return mapper.selectUser();
    }

    @Override
    public int addUser(User user) {
        return sqlSession.getMapper(UserMapper.class).addUser(user);
        // return 0;
    }

    @Override
    public int deleteUser(int id) {
        return sqlSession.getMapper(UserMapper.class).deleteUser(id);
        // return 0;
    }
}
